'''
Created on Jan 26, 2011

@author: oabalbin
'''
import pysam
from optparse import OptionParser

def read_reader(input_bam_file, location):
    '''
    location is a list of chr, start, end position
    '''
    samfile = pysam.Samfile(input_bam_file, "rb")
    
    for alignedread in samfile.fetch(location[0], location[1], location[2]):
        print alignedread
        print alignedread.cigar, alignedread.pos, alignedread.aend, alignedread.alen

    samfile.close()

if __name__ == '__main__':
        
    optionparser = OptionParser("usage: %prog [options] ")
    optionparser.add_option("-b", "--bam_file", dest="bam_file",
                            help="bam file")
    
    (options, args) = optionparser.parse_args()
    location=['chr17:',7571720,7590863]
    read_reader(options.bam_file, location)

    

    